package Boersenpro.Engine;

import Boersenpro.Engine.Settings.Constants;

public class Engine {
	private Worker worker;
	private Constants settings;
	private Constants user;
	public Engine(String userLabel){
		worker = new Worker(this);
		
	}
	public synchronized void start(){
		worker.runIt = true;
		worker.start();
	}
	public synchronized void stop(){
		worker.runIt = false;
	}
}
class Worker extends Thread{
	Engine main;
	public boolean runIt = true;
	public Worker(Engine get){
		main = get;
	}
	public void run(){
		long lastTime = System.currentTimeMillis();
		long lastSet = 0;
		int fps = 30;
		int cc = 1;
		long fc = 1000/(fps+1);
		while (runIt){
			if (cc<=fps){
				if (fc*cc<System.currentTimeMillis()-lastTime){
					//Tick
					
					cc++;
				}
			}
			if (System.currentTimeMillis()-lastTime>1000){
				if (cc>fps && fps>30){
					fps--;
				}
				if (cc<fps){
					fps++;
				}
				fc = 1000/(fps+1);
				//FPS: cc-1
				
				cc = 1;
				lastTime = System.currentTimeMillis();
			}
		}
	}
}